package shortlink.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.RequiredArgsConstructor;
import org.apache.ibatis.annotations.Delete;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import shortlink.common.convention.result.Result;
import shortlink.common.convention.result.Results;
import shortlink.dto.req.ShortLinkGroupSaveReqDTO;
import shortlink.dto.req.ShortLinkGroupSortReqDTO;
import shortlink.dto.req.ShortLinkGroupUpdateReqDTO;
import shortlink.dto.resp.ShortLinkGroupRespDTO;
import shortlink.service.GroupService;

import java.util.List;

@RestController
@RequiredArgsConstructor
public class GroupController {
    private final GroupService groupService;

    /*增加短链接分组*/
    @PostMapping("/api/short-link/admin/group/savegroup")
    public Result<Void> saveGroup(@RequestBody ShortLinkGroupSaveReqDTO requestParam) {
        groupService.saveGroup(requestParam.getName());
        return Results.success();
    }
    /*分页查询短链接分组*/
    @GetMapping("/api/short-link/admin/group/listgroup")
    public Result<List<ShortLinkGroupRespDTO>> listGroup(){
        return Results.success(groupService.listGroup());
    }
    /*修改短链接分组*/
    @PostMapping("/api/short-link/admin/group/updategroup")
    public Result<Void> updateGroup(@RequestBody ShortLinkGroupUpdateReqDTO requestParam) {
        groupService.updateGroup(requestParam);
        return Results.success();
    }
    /*删除锻短链接分组*/
    @DeleteMapping("/api/short-link/admin/group/deletegroup")
    public Result<Void> delete(@RequestParam  String gid){
        groupService.deleteGroup(gid);
        return Results.success();
    }
    /*排序短链接分组*/
    @PostMapping("/api/short-link/admin/group/sortgroup")
    public Result<Void> sortGroup(@RequestBody List<ShortLinkGroupSortReqDTO> requestParam) {
        groupService.sortGroup(requestParam);
        return Results.success();
    }

}
